home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / dev / amos / blox0_7.lha / score / score.amosSourceCode < prev   
AMOS Source Code  |  1980-09-18  |  4KB  |  212 lines

  1. '
  2. ' amospro high score routine 
  3. '
  4.  
  5.  
  6.  
  7.  
  8.  
  9. '  
  10. Dim NOM$(9),SCORE(9)
  11. Global NOM$(),SCORE()
  12. '
  13. '
  14. ' Small example
  15. '
  16. ' Close screen 0 (default) 
  17. ' Screen Close 0 
  18. '
  19. ' Load a list of scores from "Hiscores.SCR"  
  20. HISCORE_LOAD["Hiscores.SCR"]
  21. '
  22. HISCORE_ENTER[Val(Command Line$)]
  23. '
  24. ' Save the new table on the disc 
  25. HISCORE_SAVE["Hiscores.SCR"]
  26. '
  27. Timer=0
  28. JW:
  29. A=Joy(1)
  30. If Timer>250 Then Command Line$=Str$(SCORE(0)) : Run "blox"
  31. If A>15 Then Goto JW2
  32. Goto JW
  33. JW2:
  34. '
  35. ' Finally, remove the hi-score table from the screen 
  36. HISCORE_REMOVE
  37. '
  38. Command Line$=Str$(SCORE(0))
  39. Run "blox"
  40.  
  41. '
  42. 'F9 (Fold/Unfold) displays the full listings 
  43. Procedure HISCORE_DISPLAY
  44.    '
  45.    Global SCR_FLG
  46.    '
  47.    Dim C(16)
  48.    '
  49.    ' Unpack the image into screen 7, and fade it down to black  
  50.    Unpack 10 To 7 : Screen Hide 
  51.    For C=0 To 15 : C(C)=Colour(C) : Colour C,0 : Next 
  52.    '
  53.    ' This internal flag is set to one if we have to   
  54.    ' enter the name. In this case, we just copy the 
  55.    ' ENTER YOUR NAME picture to the title area at the top of the screen 
  56.      If SCR_FLG
  57.        Screen Copy 7,80,72,240,120 To 7,80,8
  58.      End If 
  59.    '
  60.    ' Erase 'Enter your name' from the screen area   
  61.    Cls 0,80,72 To 240,120
  62.    '
  63.    ' Display the 10 names using a FOR..NEXT loop  
  64.    '  
  65.    Ink 1,0,0
  66.    For I=0 To 9
  67.       YP=82+I*9
  68.       SCORE$=Mid$(Str$(SCORE(I)),2)
  69.       LS=Text Length(SCORE$)
  70.       Text 85,YP,NOM$(I)
  71.       Text 251-LS,YP,SCORE$
  72.    Next I
  73.    '
  74.    ' Now we can fade in the screen
  75.    Screen Show 
  76.    '
  77.    ' Fade the screen back to the original colours 
  78.    Fade 1,C(0),C(1),C(2),C(3),C(4),C(5),C(6),C(7),C(8),C(9),C(10),C(11),C(12),C(13),C(14),C(15)
  79.    ' Wait until the fade is over
  80.    Wait 16
  81.    '
  82.    Pop Proc
  83.    '
  84. End Proc
  85. Procedure HISCORE_REMOVE
  86.    '
  87.    ' Simply fade out the screen to black, and erase it
  88.    Fade 1 : Wait 16
  89.    Screen Close 7
  90.    '
  91. End Proc
  92. Procedure HISCORE_ENTER[SCORE]
  93.    '
  94.    Global SCR_FLG
  95.    '
  96.    If SCORE>SCORE(9)
  97.       '
  98.       ' Find the position of our new score in the table
  99.       POS=0
  100.       While SCORE<=SCORE(POS)
  101.          POS=POS+1
  102.       Wend 
  103.       '  Move the lower scores one place down  
  104.       For I=9 To POS+1 Step -1
  105.          NOM$(I)=NOM$(I-1)
  106.          SCORE(I)=SCORE(I-1)
  107.       Next I
  108.       NOM$(POS)=""
  109.       SCORE(POS)=SCORE
  110.       '
  111.       ' Display score, with the ENTER YOUR NAME picture along the title
  112.       SCR_FLG=-1 : HISCORE_DISPLAY
  113.       '
  114.       ' Set up Cursor  
  115.       Flash 15,"(FFF,30)(666,20)"
  116.       XC=100 : YC=50
  117.       '
  118.       ' Display Cursor 
  119.       Gosub CURSEUR
  120.       '
  121.       ' Input the name using a REPEAT..UNTIL loop
  122.       Repeat 
  123.          ' Read keyboard  
  124.          K$=Inkey$
  125.          K=Asc(K$)
  126.          L=Len(NOM$)
  127.          ' Handle Backspace 
  128.          If K=8 and L>0
  129.             DC=0
  130.             XC=XC-8
  131.             Text XC,YC,"  "
  132.             Gosub CURSEUR
  133.             NOM$=Left$(NOM$,L-1)
  134.          End If 
  135.          ' Handle cursor  
  136.          If K>13 and L<12
  137.             DC=8
  138.             Ink 1 : Text XC,YC,K$
  139.             XC=XC+8
  140.             Gosub CURSEUR
  141.             NOM$=NOM$+K$
  142.          End If 
  143.          '
  144.          ' Repeat until a carriage return.  
  145.       Until K=13
  146.       '
  147.       ' Put the new name into the NOM$ array 
  148.       NOM$(POS)=NOM$
  149.       SCORE(POS)=SCORE
  150.       '
  151.       ' Erase screen 
  152.       Flash Off 
  153.       HISCORE_REMOVE
  154.       SCR_FLG=0
  155.       '
  156.    End If 
  157.    '
  158.    ' Display final array, and return! 
  159.    HISCORE_DISPLAY
  160.    '
  161.    Pop Proc
  162.    '
  163.    '  Simulate a 'fake' text cursor using the DRAW command  
  164.    CURSEUR:
  165.    Ink 15 : Draw XC,YC+1 To XC+6,YC+1
  166.    Return 
  167.    '
  168. End Proc
  169. Procedure HISCORE_LOAD[N$]
  170.    '
  171.    ' Handle errors
  172.    On Error Goto ERREUR
  173.    '
  174.    ' Open a simple sequential file
  175.    Open In 1,N$
  176.    ' Read the names and scores from the disc
  177.    For I=0 To 9
  178.       Line Input #1,NOM$(I),SCORE$
  179.       SCORE(I)=Val(SCORE$)
  180.    Next I
  181.    ' Close up the file  
  182.    Close 1
  183.    '
  184.    SKIP:
  185.    Pop Proc
  186.    '
  187.    ERREUR:
  188.    Resume SKIP
  189.    '
  190. End Proc
  191. Procedure HISCORE_SAVE[N$]
  192.    '
  193.    ' Handle errors
  194.    On Error Goto ERREUR
  195.    '
  196.    ' Create a simple sequential file  
  197.    Open Out 1,N$
  198.    ' Write the names and scores to the new file 
  199.    For I=0 To 9
  200.       Print #1,NOM$(I)
  201.       Print #1,Str$(SCORE(I))
  202.    Next I
  203.    ' Close the file (ESSENTIAL!)
  204.    Close 1
  205.    '
  206.    SKIP:
  207.    Pop Proc
  208.    '
  209.    ERREUR:
  210.    Resume SKIP
  211.    '
  212. End Proc